package com.crayon.account;

import android.content.Intent;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager.NameNotFoundException;
import android.os.Bundle;
import android.os.Handler;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.LoaderManager;
import android.support.v4.content.Loader;

import com.crayon.account.data.ENMapKey;
import com.crayon.account.dummy.DummyContent;
import com.crayon.account.dummy.DummyContent.DummyItem;
import com.crayon.account.fragments.FRGListMonth;
import com.crayon.account.fragments.FRGMonthChart;
import com.crayon.account.fragments.FragmentDailyList;
import com.crayon.account.fragments.FragmentListBanks;
import com.crayon.account.fragments.FragmentListCards;
import com.crayon.account.fragments.FragmentListCateIn;
import com.crayon.account.fragments.FragmentListCateOut;
import com.crayon.account.fragments.FragmentListWrite;
import com.crayon.account.fragments.FragmentRootSearch;
import com.crayon.account.fragments.FragmentTableGrid;
import com.crayon.account.loader.LoaderSQLDBInit;
import com.crayon.sharemenu.R;
import com.crayon.util.UIBIND;

import java.util.Arrays;
import java.util.HashMap;

public class ActivityIntro extends FragmentActivity 
implements LoaderManager.LoaderCallbacks<HashMap<ENMapKey, Object>>{

	Handler EVENT = new Handler(){

	};
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);

		if(getActionBar()!=null)getActionBar().hide();
		setContentView(R.layout.activity_intro);


		try {
			PackageInfo packageInfo = getPackageManager().getPackageInfo(getPackageName(), 0);

			UIBIND.bindTextA(this, R.id.textViewVer, String.format("VER %s",packageInfo.versionName));

		} catch(NameNotFoundException e) { }

		getSupportLoaderManager().initLoader(0, null, this);
	}

	private void initStackData(){
		DummyContent.addItem(Arrays.asList(
                new DummyItem("10", getString(R.string.main_list_menutext_table_list),FragmentTableGrid.class)
				,new DummyItem("1", getString(R.string.main_list_menutext_viewmonthly),FRGListMonth.class)
				,new DummyItem("2", getString(R.string.main_list_menutext_summary),FRGMonthChart.class)
				,new DummyItem("3", getString(R.string.main_list_menutext_search),FragmentRootSearch.class)
				,new DummyItem("4", getString(R.string.main_list_menutext_insert),	  FragmentListWrite.class)
				,new DummyItem("5", getString(R.string.main_list_menutext_listcatein),	  FragmentListCateIn.class)
				,new DummyItem("6", getString(R.string.main_list_menutext_listcateout),	  FragmentListCateOut.class)
				,new DummyItem("7", getString(R.string.main_list_menutext_listcards),	  FragmentListCards.class)
				,new DummyItem("8", getString(R.string.main_list_menutext_listbanks),	  FragmentListBanks.class)
				));

	}

	private void loadAppMain(){
		initStackData();
		EVENT.postDelayed(new Runnable() {

			@Override
			public void run() {
				// TODO Auto-generated method stub
				runMain();
			}
		}, 2000);
	}
	private void runMain(){
		//		Intent intent = new Intent(this,ItemListActivity.class);
		Intent intent =new Intent(this,ActivityLeftMenus.class);
		startActivity(intent);
		finish();
	}
	@Override
	public Loader<HashMap<ENMapKey, Object>> onCreateLoader(int arg0,
			Bundle arg1) {
		// TODO Auto-generated method stub
		switch(arg0){
		case 0:
			return new LoaderSQLDBInit(this);
		}
		return null;
	}
	@Override
	public void onLoadFinished(Loader<HashMap<ENMapKey, Object>> arg0,
			HashMap<ENMapKey, Object> arg1) {
		// TODO Auto-generated method stub
		switch(arg0.getId()){
		case 0:
			loadAppMain();
			break;
		}

	}
	@Override
	public void onLoaderReset(Loader<HashMap<ENMapKey, Object>> arg0) {
		// TODO Auto-generated method stub

	}
}
